Re: problem fetching currval of sequence

Поиск
Список
Период
Сортировка
От Charles Hauser
Тема Re: problem fetching currval of sequence
Дата
Msg-id a05111b02b975aa9d9743@[152.3.11.193]
обсуждение исходный текст
Ответ на Re: problem fetching currval of sequence  (Tom Lane <tgl@sss.pgh.pa.us>)
Ответы Re: problem fetching currval of sequence  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-sql
Tom,

Quite right, I did mean to do an INSERT.  Changing the script to do so though I still get the error:
                ERROR: gb_gb_id_seq.currval is not yet defined in this session.


    foreach $id(sort keys %ACCN) {
      $conn->exec(
                                "INSERT INTO gb (clone_id,accn,gi) VALUES ( '$ACCN{$id}{clone_id}','$ACCN{$id}{gb}','$ACCN{$id}{gi}')";
                                );
        $result = $conn->exec("SELECT currval('gb_gb_id_seq');");
        die $conn->errorMessage unless PGRES_TUPLES_OK eq $result->resultStatus;
        $gb_id = $result->fetchrow;
        $ACCN{$id}{gb_id} = $gb_id;
    }


Charles Hauser <chauser@duke.edu> writes:
>      foreach $id(sort keys %ACCN) {
> $conn->exec(
>                     "UPDATE gb SET accn_no = '$ACCN{$id}{gb}',gi_no =
> '$ACCN{$id}{gi}' WHERE clone_id = '$ACCN{$id}{clone_id}'"
>                     );

> $result = $conn->exec("SELECT currval('gb_gb_id_seq');");

This isn't inserting any new row, so nextval() isn't called, so there's
nothing for currval() to work on.  Are you sure you did not mean to do
an INSERT?

If you did want an UPDATE, seems like you could do

      SELECT gb_id FROM gb WHERE clone_id = '$ACCN{$id}{clone_id}'

                    regards, tom lane


-- 
Regards,

        Chuck

В списке pgsql-sql по дате отправления:

Предыдущее
От: Oleg Bartunov
Дата:
Сообщение: Re: Transitive Closure
Следующее
От: Tom Lane
Дата:
Сообщение: Re: problem fetching currval of sequence